package com.www.dao.admin;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import com.www.domain.admin.Role;

/**
 * 角色role dao
 */
@Repository
public interface RoleDao {
	/*
	 * 角色插入操作
	 */
	@Insert("insert into role(id,name,remark) values(default,#{name},#{remark})")
	public int add(Role role);
	
	/*
	 * 修改角色信息
	 */
	@Update("update role set name = #{name},remark = #{remark} where id = #{id}")
	public int edit(Role role);
	
	/*
	 * 删除角色信息
	 */
	@Delete("delete from role where id = #{id}")
	public int delete(Long id);
	
	/*
	 * 角色信息模糊分页搜索查询
	 */
	@Select({"<script>" +
			"select * from role " +
			"<if test='name != null'> where name like '%${name}%'</if>" +
			"<if test='offset != null and pageSize != null'> limit #{offset},#{pageSize}</if>" +
		"</script>"})
	public List<Role> findList(Map<String, Object> queryMap);
	
	/*
	 * 角色信息模糊分页搜索查询总记录数
	 */
	@Select({"<script>" +
			"select count(*) from role " +
			"<if test='name != null'> where name like '%${name}%'</if>" +
		"</script>"})
	public int getTotal(Map<String, Object> queryMap);
	
	/*
	 * 根据id获取角色
	 */
	@Select("select * from role where id = #{id}")
	public Role find(Long id);
}
